<!--应收列表-->
<template>
  <div class="app-container">
    <div class="filter-container">
      <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
        <el-tab-pane v-for="item in tabMapOptions" :key="item.key" :label="item.label" :name="item.key">
          <div class="car-label">收款类型:</div>
          <el-input v-model="listQuery.title" placeholder="Title" style="width: 130px;" class="filter-item" />
          <el-button style="margin-left: 10px" class="filter-item" type="primary" icon="el-icon-search">
            搜索
          </el-button>
          <el-button class="filter-item right-btn" type="primary" icon="el-icon-download" @click="">
            作废
          </el-button>
          <ve-table
            :columns="activeName==='needSure'?commonColumns.concat(firstDiffer):columns"
            :table-data="tableData"
            row-key-field-name="id"
            :border-x="true"
            :border-y="true"
            :scroll-width="1600"
            :row-style-option="rowStyleOption"
            :checkbox-option="checkboxOptipon"
          />
          <div class="table-pagination">
            <ve-pagination
              :total="totalCount"
              :page-index="pageIndex"
              :page-size="pageSize"
              @on-page-number-change="pageNumberChange"
              @on-page-size-change="pageSizeChange"
            />
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<style scoped lang="scss">
  .table-pagination {
    margin-top: 20px;
    text-align: right;
  }
  .right-btn{
    float: right;
  }
</style>

<script>

export default {
  data() {
    return {
      // page index
      pageIndex: 1,
      dataTable: [],
      totalCount: '',
      // page size
      pageSize: 10,
      listQuery: {},
      rowStyleOption: { // 表格样式
        stripe: true, // 斑马纹
        hoverHighlight: true, // hover高亮
        clickHighlight: true // 点击行高亮
      },
      activeName: 'needSure',
      tabMapOptions: [
        {
          label: '待确认',
          key: 'needSure'
        },
        {
          label: '待收款',
          key: 'needReceived'
        },
        {
          label: '收款完成',
          key: 'Received'
        },
        {
          label: '审核完成',
          key: 'auditComplex'
        },
        {
          label: '已作废',
          key: 'invalid'
        }
      ],
      checkboxOptipon: {
        // 行选择改变事件
        selectedRowChange: ({ row, isSelected, selectedRowKeys }) => {
          console.log(row, isSelected, selectedRowKeys)
        },
        // 全选改变事件
        selectedAllChange: ({ isSelected, selectedRowKeys }) => {
          console.log(isSelected, selectedRowKeys)
        }
      },
      commonColumns: [
        {
          field: '',
          key: 'z',
          // type=checkbox
          type: 'checkbox',
          title: '',
          width: 50,
          align: 'center'
        },
        {
          field: '',
          key: 'a',
          title: '序号',
          align: 'center',
          renderBodyCell: ({ row, column, rowIndex }, h) => {
            return (this.pageIndex - 1) * this.pageSize + rowIndex + 1
          }
        },
        { field: 'name', key: 'b', title: '订单编号', align: 'center', width: '100px' },
        { field: 'name', key: 'c', title: '收款类型', align: 'center', width: '100px' },
        { field: 'date', key: 'd', title: '客户姓名', align: 'left', width: '100px' },
        { field: 'address', key: 'e', title: '车辆类别', width: '100px' },
        { field: 'address', key: 'f', title: '贷款金额', width: '100px' },
        { field: 'address', key: 'g', title: '分期金额', width: '100px' },
        { field: 'address', key: 'l', title: '应收金额', width: '100px' },
        { field: 'address', key: 'i', title: '已收金额', width: '100px' }
      ],
      firstDiffer: [
        { field: 'address', key: '1', title: '分公司', width: '100px' },
        { field: 'address', key: '2', title: '部门', width: '100px' },
        { field: 'address', key: '3', title: '业务员', width: '100px' },
        { field: 'address', key: '4', title: '贷款银行', width: '100px' },
        { field: 'address', key: '5', title: '创建时间', width: '100px' },
        { field: 'address', key: '6', title: '应收状态', width: '100px' },
        { field: 'address', key: '7', title: '收款时间', width: '100px' },
        { field: 'address', key: '8', title: '收款人', width: '100px' },
        { field: 'address', key: '9', title: '收款详情', width: '100px' }
      ],
      secondDiffer: [
        { field: 'address', key: '1', title: '收款金额', width: '100px' },
        { field: 'address', key: '2', title: '收款时间', width: '100px' },
        { field: 'address', key: '3', title: '收款人', width: '100px' },
        { field: 'address', key: '4', title: '应收状态', width: '100px' },
        { field: 'address', key: '5', title: '分公司', width: '100px' },
        { field: 'address', key: '6', title: '部门', width: '100px' },
        { field: 'address', key: '7', title: '业务员', width: '100px' },
        { field: 'address', key: '8', title: '贷款银行', width: '100px' },
        { field: 'address', key: '9', title: '创建时间', width: '100px' }
      ],
      columns: []
    }
  },
  computed: {
    // table data
    // tableData() {
    //   const { pageIndex, pageSize } = this
    //   return DB_DATA.slice((pageIndex - 1) * pageSize, pageIndex * pageSize)
    // },
    // total count
    // totalCount() {
    //   return this.tableData.length
    // }
  },
  created() {
    this.initDatabase()
  },
  methods: {
    // page number change
    pageNumberChange(pageIndex) {
      this.pageIndex = pageIndex
    },

    // page size change
    pageSizeChange(pageSize) {
      this.pageIndex = 1
      this.pageSize = pageSize
    },

    // Simulation table data
    async initDatabase() {
      this.tableData = [];
      let param = {appId:"9999",pageIndex:this.pageIndex,pageSize:this.pageSize};
      let data = await this.$http.get('/auth/distributor/get', param)
      console.log(data);
      if (data.code === 200) {
        this.tableData = data.data;
        this.totalCount = data.data.length;
      } else {

      }


      console.log(this.tableData)




    }
  }
}
</script>
